package com.zq.order.config;

import cn.hutool.core.date.DateUtil;
import com.zq.order.dao.entity.OrderStatistics;
import com.zq.order.mapper.OrderInfoMapper;
import com.zq.order.mapper.OrderStatisticsMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;

// com.atguigu.spzx.manager.task
@Component
@Slf4j
public class OrderStatisticsTask {

    @Autowired
    private OrderInfoMapper orderInfoMapper;

    @Autowired
    private OrderStatisticsMapper orderStatisticsMapper;
//    每天2点统计昨天的订单金额
    @Scheduled(cron = "0 0 2 * * ?")
    public void orderTotalAmountStatistics() {
        String createTime = DateUtil.format(new Date(), "yyyy-MM-dd");
        OrderStatistics orderStatistics = orderInfoMapper.
                selectOrderStatistics(createTime);
        if(orderStatistics != null) {
            orderStatisticsMapper.insert(orderStatistics) ;
        }

    }





}